package common;

import gui.GuiManager;

import common.di.DI;
import common.interfaces.ConfigurationsInterface;
import common.interfaces.DBInterface;
import common.interfaces.PlayInterface;
import common.interfaces.StatisticsInterface;

public class Fictionator {
	
	private static Fictionator instance;
	private final PlayInterface playLogic;
	private final StatisticsInterface statisticsLogic;
	private final ConfigurationsInterface configurationsLogic;
	private final DBInterface dbAccess;

    private int guiSessionID;
	
	public static void main(String[] args) {
	    try {
	        instance = new Fictionator();
            int guiSessionID = getInstance().getDBAccess().getNewGUISessionID();
            if (guiSessionID != -1) {
                getInstance().setGuiSessionID(guiSessionID);
                GuiManager.startGui();
            } else {    
                GuiManager.showPossibleOngoinImportDialog();
            }
	    } catch (Exception e) {
	        GuiManager.showStartupProblemDialog();
        }
	}
	
	private Fictionator() {		
		dbAccess = DI.getInstance(DBInterface.class);
		playLogic = DI.getInstance(PlayInterface.class);
		statisticsLogic = DI.getInstance(StatisticsInterface.class);
		configurationsLogic = DI.getInstance(ConfigurationsInterface.class);
	}
	
    public static Fictionator getInstance() {
        return instance;
    }

	public PlayInterface getPlayLogic() {
		return playLogic;
	}

	public StatisticsInterface getStatisticsLogic() {
		return statisticsLogic;
	}

	public ConfigurationsInterface getConfigurationsLogic() {
		return configurationsLogic;
	}

	public DBInterface getDBAccess() {
		return dbAccess;
	}

    public void setGuiSessionID(int guiSessionID) {
        this.guiSessionID = guiSessionID;
    }

    public int getGuiSessionID() {
        return guiSessionID;
    }

}
